package com.quickask.dao;

import com.quickask.entity.AsknowUserPrivilegeEntity;
import com.quickask.idao.IUserPrivilegeDao;
import com.quickask.operate.data.ResultCode;

import java.util.Map;

/**
 * Created by Administrator on 2015/9/30.
 */
public class UserPrivilegeDao extends BaseDao<AsknowUserPrivilegeEntity, Integer> implements IUserPrivilegeDao {

    /**
     * 用户注销登录
     *
     * @param userId 用户Id
     * @return
     */
    @Override
    public void logout(Integer userId) {
        AsknowUserPrivilegeEntity asknowUserPrivilegeEntity = get(userId);
        asknowUserPrivilegeEntity.setUserLoginState((byte) 0);
    }

    /**
     * 完善个人信息
     *
     * @param userId     用户id
     * @param properties 更新的属性
     * @return 返回结果码，详见com.quickask.operate.data.ResultCode.java
     */
    @Override
    public int updatePersonalImformation(Integer userId, Map<String, Object> properties) {
        AsknowUserPrivilegeEntity asknowUserPrivilegeEntity = get(userId);
        if(asknowUserPrivilegeEntity == null) {
            return ResultCode.USERID_ERROR;
        } else {
            if(properties.get("userNickname")!=null) {
                asknowUserPrivilegeEntity.setUserNickname((String) properties.get("userNickname"));
            }
            if(properties.get("userSex")!=null) {
                asknowUserPrivilegeEntity.setUserSex((Byte) properties.get("userSex"));
            }
            if(properties.get("userAge")!=null) {
                asknowUserPrivilegeEntity.setUserAge((Integer) properties.get("userAge"));
            }
            return ResultCode.SUCCESS;
        }
    }
}
